/*
 * ===========================================================================================
 * = COPYRIGHT
 *          PAX Computer Technology (Shenzhen) Co., Ltd. PROPRIETARY INFORMATION
 *   This software is supplied under the terms of a license agreement or nondisclosure
 *   agreement with PAX Computer Technology (Shenzhen) Co., Ltd. and may not be copied or
 *   disclosed except in accordance with the terms in that agreement.
 *     Copyright (C) 2023 PAX Computer Technology (Shenzhen) Co., Ltd. All rights reserved.
 * ===========================================================================================
 */

import 'package:flutter/material.dart';
import 'package:pos_link/auto_data_source/auto_data_source_common.dart';
import 'package:pos_link/auto_data_source/auto_manage_request_data_source.dart';
import 'package:pos_link/auto_data_source/auto_manage_response_data_source.dart';
import 'package:pos_link/auto_pigeon/poslink_sdk_manage.dart';
import 'package:pos_link/log/dart_log.dart';
import 'package:pos_link/model/response_db.dart';
import 'comm_setting_view_model.dart';

class ManageViewModel extends ChangeNotifier {
  Future startManage(ResponseDataBase responseDataBase, List<Map> dataSource) async {
    POSLinkManageApi ManageApi = POSLinkManageApi();

    /// command
    Map cmdData = dataSource.first;
    switch (cmdData[kValue]) {
      case ManageCommand.DeleteImageRequest:
        ManageDeleteImageRequest req = ManageReqData.formDeleteImageRequest(dataSource);
        ManageDeleteImageResponse rsp = await ManageApi.deleteImage(req);
        ManageRspData.parseRspManageDeleteImageResponse(rsp, responseDataBase.manageData);
        break;
      case ManageCommand.GetSafParametersRequest:
        ManageGetSafParametersRequest req = ManageReqData.formGetSafParametersRequest(dataSource);
        ManageGetSafParametersResponse rsp = await ManageApi.getSafParameters(req);
        ManageRspData.parseRspManageGetSafParametersResponse(rsp, responseDataBase.manageData);
        break;
      case ManageCommand.ResetMsrRequest:
        ManageResetMsrRequest req = ManageReqData.formResetMsrRequest(dataSource);
        ManageResetMsrResponse rsp = await ManageApi.resetMsr(req);
        ManageRspData.parseRspManageResetMsrResponse(rsp, responseDataBase.manageData);
        break;
      case ManageCommand.DoSignatureRequest:
        ManageDoSignatureRequest req = ManageReqData.formDoSignatureRequest(dataSource);
        ManageDoSignatureResponse rsp = await ManageApi.doSignature(req);
        ManageRspData.parseRspManageDoSignatureResponse(rsp, responseDataBase.manageData);
        break;
      case ManageCommand.RebootRequest:
        ManageRebootRequest req = ManageReqData.formRebootRequest(dataSource);
        ManageRebootResponse rsp = await ManageApi.reboot(req);
        ManageRspData.parseRspManageRebootResponse(rsp, responseDataBase.manageData);
        break;
      case ManageCommand.InitRequest:
        ManageInitRequest req = ManageReqData.formInitRequest(dataSource);
        ManageInitResponse rsp = await ManageApi.init(req);
        ManageRspData.parseRspManageInitResponse(rsp, responseDataBase.manageData);
        break;
      case ManageCommand.CheckFileRequest:
        ManageCheckFileRequest req = ManageReqData.formCheckFileRequest(dataSource);
        ManageCheckFileResponse rsp = await ManageApi.checkFile(req);
        ManageRspData.parseRspManageCheckFileResponse(rsp, responseDataBase.manageData);
        break;
      case ManageCommand.TokenAdministrativeRequest:
        ManageTokenAdministrativeRequest req = ManageReqData.formTokenAdministrativeRequest(dataSource);
        ManageTokenAdministrativeResponse rsp = await ManageApi.tokenAdministrative(req);
        ManageRspData.parseRspManageTokenAdministrativeResponse(rsp, responseDataBase.manageData);
        break;
      case ManageCommand.ReprintRequest:
        ManageReprintRequest req = ManageReqData.formReprintRequest(dataSource);
        ManageReprintResponse rsp = await ManageApi.reprint(req);
        ManageRspData.parseRspManageReprintResponse(rsp, responseDataBase.manageData);
        break;
      case ManageCommand.VasPushDataRequest:
        ManageVasPushDataRequest req = ManageReqData.formVasPushDataRequest(dataSource);
        ManageVasPushDataResponse rsp = await ManageApi.vasPushData(req);
        ManageRspData.parseRspManageVasPushDataResponse(rsp, responseDataBase.manageData);
        break;
      case ManageCommand.SetApplePayVasParametersRequest:
        ManageSetApplePayVasParametersRequest req = ManageReqData.formSetApplePayVasParametersRequest(dataSource);
        ManageSetApplePayVasParametersResponse rsp = await ManageApi.setApplePayVasParameters(req);
        ManageRspData.parseRspManageSetApplePayVasParametersResponse(rsp, responseDataBase.manageData);
        break;
      case ManageCommand.SetGoogleSmartTapParametersRequest:
        ManageSetGoogleSmartTapParametersRequest req = ManageReqData.formSetGoogleSmartTapParametersRequest(dataSource);
        ManageSetGoogleSmartTapParametersResponse rsp = await ManageApi.setGoogleSmartTapParameters(req);
        ManageRspData.parseRspManageSetGoogleSmartTapParametersResponse(rsp, responseDataBase.manageData);
        break;
      case ManageCommand.ResetRequest:
        ManageResetRequest req = ManageReqData.formResetRequest(dataSource);
        ManageResetResponse rsp = await ManageApi.reset(req);
        ManageRspData.parseRspManageResetResponse(rsp, responseDataBase.manageData);
        break;
      case ManageCommand.GetSignatureRequest:
        ManageGetSignatureRequest req = ManageReqData.formGetSignatureRequest(dataSource);
        ManageGetSignatureResponse rsp = await ManageApi.getSignature(req);
        ManageRspData.parseRspManageGetSignatureResponse(rsp, responseDataBase.manageData);
        break;
      case ManageCommand.UpdateResourceFileRequest:
        ManageUpdateResourceFileRequest req = ManageReqData.formUpdateResourceFileRequest(dataSource);
        ManageUpdateResourceFileResponse rsp = await ManageApi.updateResourceFile(req);
        ManageRspData.parseRspManageUpdateResourceFileResponse(rsp, responseDataBase.manageData);
        break;
      case ManageCommand.SetSafParametersRequest:
        ManageSetSafParametersRequest req = ManageReqData.formSetSafParametersRequest(dataSource);
        ManageSetSafParametersResponse rsp = await ManageApi.setSafParameters(req);
        ManageRspData.parseRspManageSetSafParametersResponse(rsp, responseDataBase.manageData);
        break;
      case ManageCommand.SetVariableRequest:
        ManageSetVariableRequest req = ManageReqData.formSetVariableRequest(dataSource);
        ManageSetVariableResponse rsp = await ManageApi.setVariable(req);
        ManageRspData.parseRspManageSetVariableResponse(rsp, responseDataBase.manageData);
        break;
      case ManageCommand.InputAccountRequest:
        ManageInputAccountRequest req = ManageReqData.formInputAccountRequest(dataSource);
        ManageInputAccountResponse rsp = await ManageApi.inputAccount(req);
        ManageRspData.parseRspManageInputAccountResponse(rsp, responseDataBase.manageData);
        break;
      case ManageCommand.GetVariableRequest:
        ManageGetVariableRequest req = ManageReqData.formGetVariableRequest(dataSource);
        ManageGetVariableResponse rsp = await ManageApi.getVariable(req);
        ManageRspData.parseRspManageGetVariableResponse(rsp, responseDataBase.manageData);
        break;

      default:
        throw Exception('undefined function');
      //break;
    }
  }
}
